#include     <sys/socket.h>
#include     <netinet/in.h>
#include     <arpa/inet.h>
#include     <stdio.h>
#include     <stdlib.h>
#include     <string.h>

#include     <time.h>
#define      LINE_SIZE 100
int
main(int argc, char **argv)
{
    timer_t tc;

    int     sockfd;
    struct sockaddr_in servaddr, cliaddr;

    sockfd = socket(AF_INET, SOCK_DGRAM, 0);

    memset(&servaddr, 0,sizeof(servaddr));
    servaddr.sin_family = AF_INET;
    servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
    servaddr.sin_port = htons(13);

    if(0!=bind(sockfd, (struct sockaddr *) &servaddr, sizeof(servaddr))){
        printf("bind error!\n");
        return 1;
    }

    int     n;
    socklen_t len=sizeof(cliaddr);
    char    mesg[LINE_SIZE+1];
    printf("server is ready!\n");
    for ( ; ; )
    {
        memset(mesg,0,LINE_SIZE+1);
        n = recvfrom(sockfd, mesg, LINE_SIZE, 0, (struct sockaddr *) &cliaddr, &len);
        mesg[LINE_SIZE]='\0';
        printf("the request data:%s\n",mesg);
        tc=time(0);
        snprintf(mesg, sizeof(mesg), "%.24s\r\n", ctime(&tc));
        sendto(sockfd, mesg, strlen(mesg), 0, (struct sockaddr *)&cliaddr, len);
    }

    return 0;
}



